package com.asteros.crypto.utils.content;

import com.asteros.common.util.io.IOUtil;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class WebServerCMUtils_Stub implements WebServerCMUtils
{
	//private static final String STORE_PATH =   System.getProperty("user.home") + File.separator + "new.keystore";
	protected static final String CONTENT_PATH 		= "C:\\Projects\\RKK\\testdata\\_data\\server\\";
//	protected static final String CONTENT_FILE_NAME = CONTENT_PATH + "content.pdf";
	protected static final String CONTENT_FILE_NAME = CONTENT_PATH + "a.txt";
	protected static final String SIGN_FILE_NAME 	= CONTENT_PATH + "1.sgn";
	
	public byte[] getContent(String userId, String documentId) throws Exception {
		System.out.println("WebServerCMUtils_Stub.getContent>>");

		byte[] buf = null;

		buf = IOUtil.readFully(new FileInputStream(CONTENT_FILE_NAME));

		System.out.println("WebServerCMUtils_Stub.getContent<<");
		return buf;
	}

	public byte[] getSignedData(String userId, String documentId){
		System.out.println("WebServerCMUtils_Stub.getSignedData>>");

		byte[] buf = null;

		try {
			buf = IOUtil.readFully(new FileInputStream(SIGN_FILE_NAME));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		System.out.println("WebServerCMUtils_Stub.getSignedData<<");
		return buf;
	}

	public void saveSignedData(String userId, String documentId, byte[] buf) throws Exception {
		System.out.println("WebServerCMUtils_Stub.saveSignedData>>");

		IOUtil.saveFile(buf, SIGN_FILE_NAME);

		System.out.println("WebServerCMUtils_Stub.saveSignedData<<");
	}


}

